package com.minesweeper;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class DatabaseManager {
     public static final String DB_URL = "jdbc:mysql://localhost:3306/minesweeper?serverTimezone=Asia/Shanghai";
    public static final String DB_USER = "root";
    public static final String DB_PASSWORD = "18708484686dd";
    public static void insertGameRecord(String difficulty, int elapsedSeconds, boolean isWin) {
        String sql = "INSERT INTO game_records (difficulty, elapsed_seconds, is_win, timestamp) VALUES (?, ?, ?, NOW())";
        try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
             PreparedStatement pstmt = conn.prepareStatement(sql)) {
            pstmt.setString(1, difficulty);
            pstmt.setInt(2, elapsedSeconds);
            pstmt.setBoolean(3, isWin);
            pstmt.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}